package com.jouwee.paranoia;

import java.util.Date;
import org.bukkit.block.Block;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;

/**
 *
 * @author Jouwee
 */
public class BlockEvent extends Event {

    /** Block before the event */
    private Block oldBlock;
    /** Block after the event */
    private Block newBlock;
    
    public BlockEvent(org.bukkit.event.block.BlockEvent e) {
        setDate(new Date());
        if(e instanceof BlockBreakEvent) {
            BlockBreakEvent bbe = (BlockBreakEvent) e;
            setPlayer(bbe.getPlayer());
            
//            setNewBlock(new Block);
            setOldBlock(bbe.getBlock());
        }
        if(e instanceof BlockPlaceEvent) {
            BlockPlaceEvent bpe = (BlockPlaceEvent) e;
            setPlayer(bpe.getPlayer());
            setNewBlock(bpe.getBlock());
        }
    }

    public Block getOldBlock() {
        return oldBlock;
    }

    public void setOldBlock(Block oldBlock) {
        this.oldBlock = oldBlock;
    }

    public Block getNewBlock() {
        return newBlock;
    }

    public void setNewBlock(Block newBlock) {
        this.newBlock = newBlock;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder(super.toString());
        sb.append(SEPARATOR);
        sb.append(getOldBlock());
        sb.append(SEPARATOR);
        sb.append(getNewBlock());
        return sb.toString();
    }
}
